<%@page import="com.ilibrary.web.vo.CollectVO"%>
<%@page import="com.ilibrary.utils.MyTools"%>
<%@page import="java.util.Date"%>
<%@page import="com.ilibrary.utils.MyColumnIndicator"%>
<%@page import="com.ilibrary.web.vo.BookVO"%>
<%@page import="com.ilibrary.web.vo.BorrowVO"%>
<%@page import="java.util.List"%>
<%@page import="com.ilibrary.constants.MyConstants"%>
<%@page import="com.ilibrary.web.vo.UserInfoVO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="../_common.jsp" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>个人中心</title>
<link href="<%=request.getContextPath()%>/template_css/index/index.css" rel="stylesheet" type="text/css">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/template_css/search/base.css">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/template_css/search/main.css">

<style type="text/css">
table {
	margin: 10px;
}

table .header {
	background-color: #DDD;
}

td {
	width: 100px;
}
</style>

</head>

<%
	List<BorrowVO> borrowVONewList = (List<BorrowVO>) request.getAttribute("borrowVONewList");
	List<BorrowVO> borrowVOCompList = (List<BorrowVO>) request.getAttribute("borrowVOCompList");
	List<CollectVO> collectVOList = (List<CollectVO>) request.getAttribute("collectVOList");
%>

<body>
	<%@include file="header.jsp" %>
	<div id="content" style="height: auto;overflow: hidden;">
		<div style="width: 100%;height: 25px;line-height: 30px;background-color: #FFFFCC;text-align: left;font-size: 14px;font-weight: bold;color: #A85300;">
			个人信息<a href="javascript: void(0)" onclick="updateUserPassword()" style="color: blue;float: right;margin-right: 20px;">修改密码</a>
		</div>
		<div style="width: 100%;height: 180px;">
			<table>
				<tr>
					<td style="font-weight: bold;" align="right" width="100">姓&nbsp;&nbsp;&nbsp;&nbsp;名:</td>
					<td width="300"><%=loginUser.getUserName() %></td>
				</tr>
				<tr>
					<td style="font-weight: bold;" align="right" width="100">学&nbsp;&nbsp;&nbsp;&nbsp;号:</td>
					<td><%=loginUser.getUserId() %></td>
				</tr>
				<tr>
					<td style="font-weight: bold;" align="right" width="100">性&nbsp;&nbsp;&nbsp;&nbsp;别:</td>
					<td><%=loginUser.getUserSex() %></td>
				</tr>
				<tr>
					<td style="font-weight: bold;" align="right" width="100">Email:</td>
					<td><%=loginUser.getUserEmail() %></td>
				</tr>
				<tr>
					<td style="font-weight: bold;" align="right" width="100">联系电话:</td>
					<td><%=loginUser.getUserPhone() %></td>
				</tr>
				<tr>
					<td style="font-weight: bold;" align="right" width="100">常用地址:</td>
					<td><%=loginUser.getUserAddr() %></td>
				</tr>
			</table>
		</div>
		
		<div style="width: 100%;height: 25px;line-height: 30px;background-color: #FFFFCC;text-align: left;font-size: 14px;font-weight: bold;color: #A85300;">
			借阅信息
		</div>
		<div style="width: 100%;height: auto;">
		<%
			if(borrowVONewList.size() <= 0) {
		%>
			<font style="margin: 20px;line-height: 100px;">对不起，暂无借阅记录。</font>
		<%
			}else {
		%>
			<table>
				<tr class="header">
					<td>书名</td>
					<td>书籍ID</td>
					<td>分类</td>
					<td>作者</td>
					<td>借阅日期</td>
					<td>期限</td>
					<td>借阅状态</td>
					<td>续借次数</td>
					<td>续借操作</td>
				</tr>
			<%
				BorrowVO borrowVO = null;
				for(int i=0;i<borrowVONewList.size();i++) {
					borrowVO = borrowVONewList.get(i);
			%>
				<tr>
					<td><a style="color: blue;" href="<%=request.getContextPath() %>/book/bookItem.action?bookId=<%=borrowVO.getBookId()%>" target="_blank"><%=borrowVO.getBookName() %></a></td>
					<td><%=borrowVO.getBookId() %></td>
					<td><%=borrowVO.getCategoryName() %></td>
					<td><%=borrowVO.getBookAuthor() %></td>
					<td><%=borrowVO.getBorrowDt() %></td>
				<%
					if(MyTools.getDayBetweenTwoDate(new Date(), borrowVO.getBorrowDeadline()) > 0) {
				%>
					<td style="color: red;"><%=borrowVO.getBorrowDeadline() %>(超期)</td>
				<%
					}else {
				%>
					<td><%=borrowVO.getBorrowDeadline() %></td>
				<%
					}
				%>
					<td><%=borrowVO.getBorrowStatusString() %></td>
					<td><%=borrowVO.getBorrowRenewNum() %></td>
				<%
					if(borrowVO.getBorrowRenewNum() < MyConstants.BORROW_RENEW_NUM_MAX) {
				%>
					<td><a href="javascript: void(0)" onclick="doRenew(<%=borrowVO.getBorrowId() %>)" style="color: blue;cursor: pointer;">续借</a></td>
				<%
					} else {
				%>
					<td>暂无操作</td>
				<%
					}
				%>
				</tr>
				
			<%
				}
			%>
			</table>
		<%	
			}
		%>
		</div>
		
		<div style="width: 100%;height: 25px;line-height: 30px;background-color: #FFFFCC;text-align: left;font-size: 14px;font-weight: bold;color: #A85300;">
			借阅历史
		</div>
		<div style="width: 100%;height: auto;">
		<%
			if(borrowVOCompList.size() <= 0) {
		%>
			<font style="margin: 20px;line-height: 100px;">对不起，暂无借阅历史。</font>
		<%
			}else {
		%>
			<table>
				<tr class="header">
					<td>书名</td>
					<td>书籍ID</td>
					<td>分类</td>
					<td>作者</td>
					<td>借阅日期</td>
					<td>期限</td>
					<td>借阅状态</td>
					<td>续借次数</td>
					<td>归还日期</td>
				</tr>
			<%
				BorrowVO borrowVOComp = null;
				for(int i=0;i<borrowVOCompList.size();i++) {
					borrowVOComp = borrowVOCompList.get(i);
			%>
				<tr>
					<td><a style="color: blue;" href="<%=request.getContextPath() %>/book/bookItem.action?bookId=<%=borrowVOComp.getBookId()%>" target="_blank"><%=borrowVOComp.getBookName() %></a></td>
					<td><%=borrowVOComp.getBookId() %></td>
					<td><%=borrowVOComp.getCategoryName() %></td>
					<td><%=borrowVOComp.getBookAuthor() %></td>
					<td><%=borrowVOComp.getBorrowDt() %></td>
					<td><%=borrowVOComp.getBorrowDeadline() %></td>
					<td><%=borrowVOComp.getBorrowStatusString() %></td>
					<td><%=borrowVOComp.getBorrowRenewNum() %></td>
					<td><%=MyTools.formatDt2(borrowVOComp.getUpdateDt()) %></td>
				</tr>
			<%
				}
			%>
			</table>
		<%
			}
		%>
		</div>
		
		<div style="width: 100%;height: 25px;line-height: 30px;background-color: #FFFFCC;text-align: left;font-size: 14px;font-weight: bold;color: #A85300;">
			图书收藏
		</div>
		<div style="width: 100%;height: auto;">
		<%
			if(collectVOList.size() <= 0) {
		%>
			<font style="margin: 20px;line-height: 100px;">对不起，暂无收藏记录。</font>
		<%
			}else {
		%>
			<table>
				<tr class="header">
					<td>书名</td>
					<td>书籍ID</td>
					<td>分类</td>
					<td>作者</td>
					<td>状态</td>
					<td>操作</td>
				</tr>
			<%
				CollectVO collectVO = null;
				for(int i=0;i<collectVOList.size();i++) {
					collectVO = collectVOList.get(i);
			%>
				<tr>
					<td><a style="color: blue;" href="<%=request.getContextPath() %>/book/bookItem.action?bookId=<%=collectVO.getBookId()%>" target="_blank"><%=collectVO.getBookName() %></a></td>
					<td><%=collectVO.getBookId() %></td>
					<td><%=collectVO.getCategoryName() %></td>
					<td><%=collectVO.getBookAuthor() %></td>
					<td><%=collectVO.getBookStatusString() %></td>
					<td><a href="javascript: void(0)" style="color: blue;" onclick="deleteCollect('<%=collectVO.getCollectId() %>')">取消收藏</a></td>
				</tr>
			<%
				}
			%>
			</table>
		<%
			}
		%>
		</div>
		<div style="width: 100%;height: 30px;clear: both;"></div>
	</div>
	<%@include file="footer.jsp" %>
</body>

<script type="text/javascript">
	function doRenew(borrowId) {
		$.ajax({
			url: '/iLibrary/borrow/ajaxDoRenew.action',
			data: {
				'borrowId': borrowId
			},
			type: 'post',
			dataType: 'json',
			async: 'false',
			success: function(msg) {
				alert("续借成功！");
				location.href = "";
			}
		});
	}
	
	function deleteCollect(collectId) {
		$.ajax({
			url: '/iLibrary/collect/ajaxDoDeleteCollect.action',
			data: {
				'collectId': collectId
			},
			type: 'post',
			dataType: 'json',
			async: 'false',
			success: function(msg) {
				if(!msg.success) {
					alert(msg.error);
					location.href = "";
				}else {
					alert("操作成功！");
					location.href = "";
				}
			}
		});
	}
	
	function updateUserPassword() {
		location.href = "<%=request.getContextPath() %>/client/updateUserPassword.action";
	}
</script>

</html>